home *** CD-ROM | disk | FTP | other *** search
/ The CICA Windows Explosion! / The CICA Windows Explosion! - Disc 2.iso / winsock / wschesb1.zip / SRC / MSWDSP.C < prev    next >
C/C++ Source or Header  |  1994-03-15  |  7KB  |  294 lines

  1. /*
  2.   C source for Winsock Chess
  3.   
  4.   Revision 1994-03-15
  5.   Modified by Donald Munro for use as a 2 player chess game over a 
  6.   WINSOCK layer on a TCP (or other WinSock supporting) network.
  7.   Source code and make files for MS Visual C/C++ V1.00/1.50.
  8.   February/March 1994
  9.   All GNU copyright and distribution conditions as described below and in the
  10.   file COPYING also apply to WinSock Chess.
  11.   This module is adapted from GNU Chess.
  12.  
  13.   C source for GNU CHESS
  14.  
  15.   Revision: 1990-09-30
  16.  
  17.   Modified by Daryl Baker for use in MS WINDOWS environment
  18.  
  19.   Copyright (C) 1986, 1987, 1988, 1989, 1990 Free Software Foundation, Inc.
  20.   Copyright (c) 1988, 1989, 1990  John Stanback
  21.  
  22.   This file is part of CHESS.
  23.  
  24.   CHESS is distributed in the hope that it will be useful, but WITHOUT ANY
  25.   WARRANTY.  No author or distributor accepts responsibility to anyone for
  26.   the consequences of using it or for whether it serves any particular
  27.   purpose or works at all, unless he says so in writing.  Refer to the CHESS
  28.   General Public License for full details.
  29.  
  30.   Everyone is granted permission to copy, modify and redistribute CHESS, but
  31.   only under the conditions described in the CHESS General Public License.
  32.   A copy of this license is supposed to have been given to you along with
  33.   CHESS so you can know your rights and responsibilities.  It should be in a
  34.   file named COPYING.  Among other things, the copyright notice and this
  35.   notice must be preserved on all copies.
  36. */
  37.  
  38. #define NOATOM 
  39. #define NOCLIPBOARD
  40. #define NOCREATESTRUCT
  41. #define NOSOUND
  42. #define NOWH
  43. #define NOCOMM
  44. #define NOKANJI
  45.  
  46. #define STRICT
  47. #include <windows.h>
  48. #include <windowsx.h>
  49. #include <string.h>
  50. #include <stdio.h>
  51.  
  52. #include "gnuchess.h"
  53. #include "chess.h"
  54. #include "defs.h"
  55. #include "stats.h"
  56.  
  57. extern short boarddraw[64];
  58. extern short colordraw[64];
  59. extern HWND hwndStatus;
  60.  
  61. extern char mvstr[4][6];
  62. extern long evrate;
  63. static char* ColorStr[2] = {"White", "Black"};
  64.  
  65. void
  66. ShowDepth (char ch)
  67. {
  68.    char tmp[30];
  69.    if ( hStats ) {
  70.       wsprintf ( tmp, "%d%c", Sdepth, ch);
  71.       SetDlgItemText ( hStats, DEPTHTEXT, tmp);
  72.    }
  73. }
  74.  
  75. void
  76. ShowScore (short score)
  77. {
  78.    char tmp[30];
  79.    if ( hStats) {
  80.       wsprintf ( tmp, "%d",score);
  81.       SetDlgItemText ( hStats, SCORETEXT, tmp);
  82.    }
  83. }
  84.  
  85. void
  86. ShowMessage (HWND hWnd, char *s)
  87. {
  88.   MessageBox ( hWnd, s, "Chess", MB_OK | MB_ICONEXCLAMATION | MB_APPLMODAL);
  89. }
  90.  
  91. void SMessageBox ( HWND hWnd, int str_num, int str1_num )
  92. {
  93.    char str[80], str1[20];
  94.    LoadString ( GetWindowInstance(hWnd), str_num, str, sizeof ( str ) );
  95.    LoadString ( GetWindowInstance(hWnd), str1_num, str1, sizeof ( str1 ) );
  96.    MessageBox ( hWnd, str, str1, MB_OK | MB_ICONEXCLAMATION | MB_APPLMODAL );
  97. }
  98.  
  99. void
  100. ClearMessage (void)
  101. {
  102. }
  103.  
  104. void
  105. ShowCurrentMove (short int pnt, short int f, short int t)
  106. {
  107.    char tmp[30];
  108.  
  109.    if ( hStats) {
  110.       algbr (f, t, false);
  111.       wsprintf ( tmp, "(%2d) %4s",pnt, (char far *)mvstr[0]);
  112.       SetDlgItemText ( hStats, POSITIONTEXT, tmp);
  113.    }
  114. }
  115.  
  116. void
  117. ShowPrompt (void)
  118. {
  119. }
  120.  
  121. void
  122. ShowNodeCnt (long int NodeCnt, long int evrate)
  123. {
  124.    char tmp[40];
  125.  
  126.    if ( hStats ) {
  127.       wsprintf ( tmp,"%-8ld", NodeCnt);
  128.       SetDlgItemText ( hStats, NODETEXT, tmp);
  129.       wsprintf ( tmp,"%-5ld", evrate);
  130.       SetDlgItemText ( hStats, NODESECTEXT, tmp);
  131.    }
  132. }  
  133.  
  134. void
  135. ShowResults (short int score, short unsigned int *bstline, char ch)
  136. {
  137.   unsigned char d, ply;
  138.   char str[300];
  139.   int s;
  140.  
  141.   if (flag.post)
  142.     {
  143.       ShowDepth (ch);
  144.       ShowScore (score);
  145.       d = 7; s = 0;
  146.       for (ply = 1; bstline[ply] > 0; ply++)
  147.         {
  148.          algbr ((short) bstline[ply] >> 8, (short) bstline[ply] & 0xFF, false);
  149.          if ( ply==5 || ply==9 || ply==13 || ply==17)
  150.             s += wsprintf ( str+s,"\n");
  151.          s += wsprintf ( str+s,"%-5s ", (char far *) mvstr[0]);
  152.         }
  153.       SetDlgItemText ( hStats, BSTLINETEXT, (LPSTR) str);
  154.     }
  155. }
  156.  
  157. void
  158. SearchStartStuff (short int side)
  159. {
  160. }
  161.  
  162. void OutputMove (HWND hWnd)
  163. //-------------------------
  164. {
  165.   char tmp[30];
  166.  
  167. /*
  168.   UpdateDisplay (hWnd, root->f, root->t, 0, (short) root->flags); */
  169.   wsprintf ((LPSTR)tmp, (LPSTR)"My move is %s",(LPSTR) mvstr[0]);
  170.   SetWindowText (hComputerMove, tmp);
  171.   if (IsIconic(hWnd))
  172.     ShowWindow(hWnd,SW_SHOW);
  173.   BringWindowToTop(hWnd);
  174. /*
  175.  
  176.   if (root->flags & draw)
  177.     SMessageBox ( hWnd, IDS_DRAWGAME,IDS_CHESS);
  178.   else if (root->score == -9999)
  179.     SMessageBox ( hWnd, IDS_YOUWIN, IDS_CHESS);
  180.   else if (root->score == 9998)
  181.     SMessageBox ( hWnd, IDS_COMPUTERWIN,IDS_CHESS);
  182.   else if (root->score < -9000)
  183.     SMessageBox ( hWnd, IDS_MATESOON,IDS_CHESS);
  184.   else if (root->score > 9000)
  185.     SMessageBox ( hWnd, IDS_COMPMATE,IDS_CHESS);
  186. */    
  187. /*    
  188.   if (flag.post)
  189.     {
  190.       ShowNodeCnt (NodeCnt, evrate); */
  191. /*
  192.       for (i = 1999; i >= 0 && Tree[i].f == 0 && Tree[i].t == 0; i--);
  193.       printz ("Max Tree= %5d", i);
  194.  
  195.     } */
  196. }
  197.  
  198. void ClockString(char *tmp)
  199. //-------------------------
  200. {
  201.   short m, s;
  202.  
  203.   m = (short) (et / 60);
  204.   s = (short) (et - 60 * (long) m);
  205.   if (TCflag)
  206.     {
  207.       m = (short) ((TimeControl.clock[player] - et) / 60);
  208.       s = (short) (TimeControl.clock[player] - et - 60 * (long) m);
  209.     }
  210.   if (m < 0) m = 0;
  211.   if (s < 0) s = 0;
  212.  
  213.   wsprintf (tmp,"%0d:%02d",m,s);
  214. }
  215.  
  216. void
  217. ShowPostnValue (short int sq)
  218. {
  219. }
  220.  
  221. void
  222. ShowPostnValues (void)
  223. {
  224. }
  225.  
  226. void DrawPiece ( HWND hWnd, short int f )
  227. {
  228.    POINT aptl[4];
  229.    HRGN hRgn;
  230.    int x,y;
  231.  
  232.    if ( flag.reverse ) {
  233.      x = 7-(f%8);
  234.      y = 7-(f/8);
  235.    } else {
  236.       x = f%8;
  237.       y = f/8;
  238.    }
  239.  
  240.    QuerySqCoords ( x,y, aptl+0);
  241.    hRgn = CreatePolygonRgn( aptl, 4, WINDING);
  242.    InvalidateRgn ( hWnd, hRgn, FALSE );
  243.    DeleteObject ( hRgn);
  244. }
  245.  
  246. void
  247. UpdateDisplay (HWND hWnd, short int f, short int t, short int redraw, short int isspec)
  248. {
  249.   short sq;
  250.   
  251.   for (sq=0; sq<64; sq++) {
  252.          boarddraw[sq] = board[sq];
  253.          colordraw[sq] = color[sq];
  254.   }
  255.  
  256.   if (redraw)
  257.   {
  258.       InvalidateRect ( hWnd, NULL, TRUE);
  259.       RedrawStatusBar();
  260.       UpdateWindow ( hWnd );
  261.   } else {
  262.       DrawPiece (hWnd, f);
  263.       DrawPiece (hWnd, t);
  264.       if (isspec & cstlmask)
  265.         if (t > f)
  266.           {
  267.             DrawPiece (hWnd, f + 3);
  268.             DrawPiece (hWnd, t - 1);
  269.           }
  270.         else
  271.           {
  272.             DrawPiece (hWnd, f - 4);
  273.             DrawPiece (hWnd, t + 1);
  274.           }
  275.       else if (isspec & epmask)
  276.         {
  277.           DrawPiece (hWnd, t - 8);
  278.           DrawPiece (hWnd, t + 8);
  279.         }
  280.       UpdateWindow (hWnd);
  281.     }
  282. }
  283.  
  284. void
  285. GiveHint (HWND hWnd)
  286. {
  287.   char s[40];
  288.   algbr ((short) (hint >> 8), (short) (hint & 0xFF), false);
  289.   strcpy (s, "try ");
  290.   strcat (s, mvstr[0]);
  291.   ShowMessage (hWnd, s);
  292. }
  293.  
  294.